<include file="Public:head"/>
<div class="main-container" id="main-container">
    <div class="main-container-inner">
        <include file="Public:left" />
        <div class="main-content">
            <div class="breadcrumbs" id="breadcrumbs">
                <ul class="breadcrumb">
                    <li><i class="icon-home home-icon"></i><a href="__APP__/{$Think.MODULE_NAME}">首页</a></li>
                    <li><a href="{:U('Taobao/lists')}">淘宝商品管理</a></li>
                    <li class="active">淘宝商品列表</li>
                </ul>
            </div>
            <div class="page-content">
                <div class="row">
                    <div class="col-xs-12">
                        <div class="row">
                            <div class="col-xs-12">
                                <div class="header smaller lighter blue">
                                    <div class="nav-search col-xs-10" id="nav-search">
                                        <form class="form-search" method="get" action="{:U('Taobao/lists')}">
                                            <div class="search_area">
                                                <select name="is_collect" autocomplete="off">
                                                    <option value="">请选择采集状态</option>
                                                      <option value="-1" <if condition="$is_collect eq -1">selected</if>>失败</option>
                                                    <option value="1" <if condition="$is_collect eq 1">selected</if>>成功</option>
                                                  <option value="0" <if condition="$is_collect eq 0 && $is_collect !=''">selected</if>>未采集</option>
                                                </select>
                                                 <select name="push_id" autocomplete="off">
                                                    <option value="">请选择推送状态</option>
                                                      <option value="-1" <if condition="$push_id eq -1">selected</if>>未推送</option>
                                                    <option value="1" <if condition="$push_id gt 0">selected</if>>已推送</option>
                                                </select>
                                                <input class="form-control search-query" type="text" name="keywords" autocomplete="off"  placeholder="请输入淘宝商品名称" value="{$Think.get.keywords}">
                                                <button class="btn btn-purple btn-sm" type="submit">搜 索 <i class="icon_search icon-on-right bigger-110"></i></button>
                                            </div>
                                        </form>
                                    </div>
                                    <div class="visible-md visible-lg hidden-sm hidden-xs action-buttons">
                                        <a class="red" data-toggle="modal" onclick="targetDelTable(0)"  data-rel="tooltip" data-original-title="批量删除">
                                            <i class="icon-trash bigger-130"></i>
                                        </a>
                                        <input class="form-control" type="text" id="url" autocomplete="off"  placeholder="链接" style="width:600px" />

                                        <button class="btn btn-purple btn-sm" type="button" onclick="remote_collect_goods()">远程采集</button>
                                        <button class="btn btn-purple btn-sm" type="button" onclick="update_content()">完善内容</button>
                                        <button class="btn btn-purple btn-sm" type="button" onclick="push_batch()">批量推送</button>
                                        <button class="btn btn-purple btn-sm" type="button" onclick="length_delete()">长度标题删除</button>
                                    </div>
                                    <div class='cl'></div>
                                </div>
                                <notempty name='lists'>
                                    <div class="table-responsive">
                                        <table id="sample-table-1" class="table table-striped table-bordered table-hover">
                                            <tbody>
                                                <tr>
                                                    <th class="center" width='45px'>
                                                        <label>
                                                            <input type="checkbox" class="ace"  autocomplete="off"/>
                                                            <span class="lbl"></span>
                                                        </label>
                                                    </th>
                                                    <th width="40px">ID</th>
                                                    <th>标题</th>
                                                    <th>来源</th>
                                                    <th>价格</th>
                                                    <!--                                                    <th>内容</th>-->
                                                    <th>长度</th>
                                                     <th>是否重复</th>
                                                    <th>是否采集</th>
                                                    <th>是否推送</th>
                                                    <th style="width:130px;"><input type="checkbox" id="dels" autocomplete="off" onclick="checkAll($(this));" />操作</th>
                                                </tr>
                                            <notempty  name="lists">

                                                <foreach name="lists" key="key" item="row">
                                                    <tr id="del_{$row.id}">
                                                        <td class="center">
                                                            <label><input type="checkbox" class="ace" name="ids" value="{$row.id}" autocomplete="off" /><span class="lbl"></span></label>
                                                        </td>
                                                        <td>{$row.id}</td>
                                                        <td style="text-align: left">{$row.title}</td>
                                                        <td style="text-align: left"><a class="blue" style="text-decoration:underline" target="_balnk" href="{$row.shorturl}">{$row.shorturl}</a></td>
                                                        <td style="text-align: left">{$row.price}</td>
                                                        <!--                                                        <td style="text-align: left;">{$row.content|msubstr=0,100,'utf-8',false}</td>-->
                                                        <td style="text-align: left">{$row.content_length}</td>
                                                            <td style="text-align: left">{$row.is_repeat}</td>
                                                        <td style="text-align: left">{$row.is_collect}</td>
                                                        <td style="text-align: left">{$row.push_id}</td>
                                                        <td>
                                                            <a onclick="targetDelTable('{$row.id}')">删除</a>
                                                        </td>
                                                    </tr>
                                                </foreach>
                                                <else/>
                                                <tr>
                                                    <td colspan="7">没有找到相关数据。</td>
                                                </tr>

                                            </notempty>
                                            </tbody>
                                        </table>
                                    </div>
                                    <div id="grid-pager" class="ui-state-default  ui-corner-bottom" dir="ltr">
                                        <table width='100%' data-table='taobao_collect' data-delete="2" id='modal_del_table'>
                                            <tr>
                                                <td>

                                                </td>
                                                <td class='td_pager'><div class='pager'>{$page}</div></td>
                                            </tr>
                                        </table>
                                    </div>
                                    <else/>
                                    <p class='noempty'>没有符合条件的记录！</p>
                                </notempty>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <include file="Public:setting" />
    </div>
</div>
<include file="Public:del" />
<include file="Public:state" />
<include file="Public:foot" />
<script>
    function remote_collect_goods() {
        //远程采集
        get_page_goods(1)

    }
    function get_page_goods(page) {
        var url = $("#url").val();
        if (url == '') {
            alert('请输入url');
            return
        }
        $.ajax({
            type: "POST",
            url: "/Tian/Taobao/collect_goods",
            data: {'url': url, 'page': page},
            dataType: 'json',
            success: function(data) {
                console.log("data", data)
                if (data.total >= 20) {
                    var page = parseInt(data.page) + 1;
              
                  get_page_goods(page)
                } else {
                    alert("已采集" + data.success)
                    location.reload()
                }

            }
        });
    }
    function update_content() {
        var ids = '';
        $("input[name='ids']").each(function() {
            if ($(this).prop("checked") == true) {
                ids += $(this).val() + ",";
            }
        });
        if (ids == '') {
            alert("请选择！");
            return false;
        }
        $.ajax({
            type: "POST",
            url: "/Tian/Taobao/update_content",
            data: {ids: ids},
            success: function(data) {
                if (data > 0) {
                    update_content()
                } else {
                    alert("已更新完毕")
                    location.reload()
                }
                console.log("data", data)

            }
        });
    }
    function push_batch(ids) {
        var ids = '';
        $("input[name='ids']").each(function() {
            if ($(this).prop("checked") == true) {
                ids += $(this).val() + ",";
            }
        });
        $.ajax({
            type: "POST",
            url: "/Tian/Taobao/push_batch",
            data: {ids: ids},
            success: function(data) {
                console.log("data", data)

                if (data > 0) {
 push_batch(ids)
                } else {
                    alert('推送结束')
//                        deleteLength()
                }
            }
        });
    }
     function length_delete(){
                $.ajax({
                    type: "POST",
                    url: "/Tian/Taobao/length_delete",
                    success: function(data){
                        if(data>0){
                                 alert("已删除"+data+"条");
                     
                        }else{
                                 alert("没有要删除的了");
                        }
                        
                    }
                });
         }
</script>
